package LeetCode.leetcode209;

public class Review1 {
    public int minSubArrayLen(int target, int[] nums) {
        if(nums.length == 0)
            return 0;
        int l = 0, r=0;
        int sum = 0;
        int ans = Integer.MAX_VALUE;
        for (; r < nums.length; r++) {
            sum += nums[r];
            if (sum >= target){
                ans = Math.min(ans, r-l+1);
            }
            while (sum >= target){
                ans = Math.min(ans, r-l+1);
                sum -= nums[l++];
            }
        }
        return ans == Integer.MAX_VALUE ? 0 : ans;
    }
}
